package com.baturu.mybatisminus.util;

/**
 * SqlFragments
 *
 * @author huangbin
 **/
public class SqlFragments {

    public static String getIfFragment(String condition, String content) {
        return "\n<if test='" + condition + "'>" + content + "</if>";
    }

    public static String getInForeachFragment(String collectionName) {
        StringBuilder sb = new StringBuilder();
        sb.append("\n<foreach item='item' index='index' open='(' close=')' collection='").append(collectionName).append("' separator=','>");
        sb.append("\n#{item}");
        sb.append("\n</foreach>");
        return sb.toString();
    }

    public static String getInForeachFragment() {
        return getInForeachFragment("collection");
    }

    public static String getSaveForeachFragment(String content) {
        StringBuilder sb = new StringBuilder();
        sb.append("\n<foreach item='item' index='index' collection='collection' open='' separator=',' close=''>");
        sb.append("\n(").append(content).append(")");
        sb.append("\n</foreach>");
        return sb.toString();
    }


    public static String getParam(String content) {
        return "#{" + content + "}";
    }
}
